﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Media;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Burning : Form
    {
        private Timer clock;
        public bool done = false;

        public Burning()
        {
            this.CenterToParent();
            InitializeComponent();

            timerMethod();
        }
        void timerMethod()
        {
        
            clock = new Timer();
            clock.Interval = 200;
            clock.Tick += new EventHandler(clock_Tick);
            clock.Start();
            
        }

        void clock_Tick(object sender, EventArgs e)
        {
            progressBar1.PerformStep();
            progressBar1.Refresh();
            // System.Console.WriteLine("dsf");
            //   textBox1.Text = "" + progressBar1.Value;

            if (progressBar1.Value == 100)
            {
                clock.Stop();
         
                string soundClipLocation = Path.GetDirectoryName(Application.ExecutablePath).Replace("\\bin\\Debug", "\\Sounds\\ding.wav");
                SoundPlayer sp = new SoundPlayer(soundClipLocation);
                sp.Play();
                ProcessCDTray(true);
                MessageBox.Show("Pictures successfully copied to disc");
              
                Close();
                done = true;
            }
        }

        public void sss()
        {
            clock.Start();
        }

        private void Form2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        // Handle Closing of the Form.
        //protected override void OnClosing(CancelEventArgs e)
        //{
        //    clock.Stop();


        //    base.OnClosing(e);
        //}

        //Win32 API Call
        [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)]
        protected static extern int mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, IntPtr hwndCallback);

        //Method
        #region Open/Close CD Tray
        ///
        /// method to open or close the CD tray based on the
        /// boolean value passed
        ///
        ///
        ///
        public bool ProcessCDTray(bool open)
        {
            int ret = 0;
            //do a switch of the value passed
            switch (open)
            {
                case true: //true = open the cd
                    ret = mciSendString("set cdaudio door open", null, 0, IntPtr.Zero);
                    return true;
                    break;
                case false: //false = close the tray
                    ret = mciSendString("set cdaudio door closed", null, 0, IntPtr.Zero);
                    return true;
                    break;
                default:
                    ret = mciSendString("set cdaudio door open", null, 0, IntPtr.Zero);
                    return true;
                    break;
            }
        }
        #endregion 

        private void button1_Click_1(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Minimized;
        }


        private void Burning_Resize_1(object sender, EventArgs e)
        {
            if (FormWindowState.Minimized == WindowState)
            {
                Hide();
                //timerMethod();
      
            }
        }

        private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {
            Show();
            WindowState = FormWindowState.Normal;

        }


    }
}
